﻿using System.Data.Entity;
using Turquoise.DataAccess.EntityFramework.Abstract;
using Turquoise.DataAccess.EntityFramework.Mappings;
using Turquoise.Entities.Data;

namespace Turquoise.DataAccess.EntityFramework
{
    public class DatabaseContext : DbContext, IDatabaseContext
    {
        public IDbSet<T> Set<T>() where T : class
        {
            return base.Set<T>();
        }

        static DatabaseContext()
        {
            Database.SetInitializer<DatabaseContext>(null);
        }

        public DatabaseContext() : base("Name=DatabaseContext")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new ContentMapping());
            modelBuilder.Configurations.Add(new ContentCategoryMapping());
            modelBuilder.Configurations.Add(new ContentCategoryHistoryMapping());
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new ContentHistoryMapping());
            modelBuilder.Configurations.Add(new ContentLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new ContentTypeMapping());
            modelBuilder.Configurations.Add(new ContentTypeHistoryMapping());
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new FileMapping());
            modelBuilder.Configurations.Add(new FileHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordMapping());
            modelBuilder.Configurations.Add(new KeywordHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new LanguageMapping());
            modelBuilder.Configurations.Add(new LanguageHistoryMapping());
            modelBuilder.Configurations.Add(new MenuMapping());
            modelBuilder.Configurations.Add(new MenuHistoryMapping());
            modelBuilder.Configurations.Add(new MenuItemMapping());
            modelBuilder.Configurations.Add(new MenuItemHistoryMapping());
            modelBuilder.Configurations.Add(new MenuItemLanguageLineMapping());
            modelBuilder.Configurations.Add(new MenuItemLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new MenuLanguageLineMapping());
            modelBuilder.Configurations.Add(new MenuLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new RoleMapping());
            modelBuilder.Configurations.Add(new RoleHistoryMapping());
            modelBuilder.Configurations.Add(new RoleLanguageLineMapping());
            modelBuilder.Configurations.Add(new RoleLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new RoleUserGroupLineMapping());
            modelBuilder.Configurations.Add(new RoleUserGroupLineHistoryMapping());
            modelBuilder.Configurations.Add(new SessionMapping());
            modelBuilder.Configurations.Add(new SessionHistoryMapping());
            modelBuilder.Configurations.Add(new SettingMapping());
            modelBuilder.Configurations.Add(new SettingHistoryMapping());
            modelBuilder.Configurations.Add(new SettingLanguageLineMapping());
            modelBuilder.Configurations.Add(new SettingLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserMapping());
            modelBuilder.Configurations.Add(new UserGroupMapping());
            modelBuilder.Configurations.Add(new UserGroupHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupLanguageLineMapping());
            modelBuilder.Configurations.Add(new UserGroupLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupRoleLineMapping());
            modelBuilder.Configurations.Add(new UserGroupRoleLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupUserLineMapping());
            modelBuilder.Configurations.Add(new UserGroupUserLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserHistoryMapping());

            modelBuilder.Entity<User>().Ignore(t => t.ConfirmPassword);
            modelBuilder.Entity<User>().Ignore(t => t.OldPassword);
            modelBuilder.Entity<ContentCategoryLanguageLine>().Ignore(t => t.ParentNames);
        }
    }
}
